﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BotonJXC.Entity;
using BotonJXC.BLL;
using BotonJXC.Util;

namespace BotonJXC.Forms
{
    public partial class ReturnOfGoodsMainForm : BaseMdiForm
    {
        private ReturnedBlls returnedBlls = null;
        private int pageNo = 0;
        public ReturnOfGoodsMainForm()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 窗体初始化事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ReturnOfGoodsMainForm_Load(object sender, EventArgs e)
        {
            if (returnedBlls == null)
            {
                initComboBoxDate();
                ReturnBllsDataGridView.DataSource = new BindingList<ReturnedProducts>();
            }
            else {
                initFormData();
            }
        }

        /// <summary>
        /// 点击增加按钮增加货品行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButtonAddProduct_Click(object sender, EventArgs e)
        {
            BindingList<ReturnedProducts> staticlist = (BindingList<ReturnedProducts>)ReturnBllsDataGridView.DataSource;
            ReturnedProducts _product = new ReturnedProducts();
            staticlist.Add(_product);
            ReturnBllsDataGridView.Refresh();
        }

        /// <summary>
        /// 点击删除按钮删除货品行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButtonDelProduct_Click(object sender, EventArgs e)
        {
            BindingList<ReturnedProducts> staticlist = (BindingList<ReturnedProducts>)ReturnBllsDataGridView.DataSource;
            foreach(DataGridViewRow row in ReturnBllsDataGridView.SelectedRows){
                staticlist.Remove((ReturnedProducts)row.DataBoundItem);
                //ReturnBllsDataGridView.Rows.Remove(row);
            }
            notifyandrealQuantityCount();
            ReturnBllsDataGridView.Refresh();
        }

       
        /// <summary>
        /// 单元格编辑完成事件 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ReturnBllsDataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (ReturnBllsDataGridView.Columns[e.ColumnIndex].Name == "ProductCode")
            {
                string productCode = Utils.ToString(ReturnBllsDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value);
                if (productCode != null && !"".Equals(productCode))
                {
                    Product product = new ProductBLL().GetProductByCode(productCode);
                    if (product != null)
                    {
                        //货品条码
                        ReturnBllsDataGridView.Rows[ReturnBllsDataGridView.CurrentRow.Index].Cells["Barcode"].Value = product.Barcode;
                        //货品名称
                        ReturnBllsDataGridView.Rows[ReturnBllsDataGridView.CurrentRow.Index].Cells["ProductName"].Value = product.ProductName;
                        //包装规格
                        ReturnBllsDataGridView.Rows[ReturnBllsDataGridView.CurrentRow.Index].Cells["PackSpec"].Value = product.PackSpec;
                        //退货进价
                        ReturnBllsDataGridView.Rows[ReturnBllsDataGridView.CurrentRow.Index].Cells["PurPrice"].Value = product.PurPrice;
                        //单位
                        ReturnBllsDataGridView.Rows[ReturnBllsDataGridView.CurrentRow.Index].Cells["DefUnit"].Value = product.DefUnit.UnitName;
                        //货品
                        ReturnBllsDataGridView.Rows[ReturnBllsDataGridView.CurrentRow.Index].Cells["Product"].Value = product;
                        //未税进价=退货进价
                        //ReturnBllsDataGridView.Rows[ReturnBllsDataGridView.CurrentRow.Index].Cells["ReturnedPrice"].Value = product.PurPrice;
                    }
                }
            }
            else if (ReturnBllsDataGridView.Columns[e.ColumnIndex].Name == "NotifyQuantity")
            {
               //计算当前行的通知金额
               double notifyQuantity = Utils.ToDouble(ReturnBllsDataGridView.Rows[ReturnBllsDataGridView.CurrentRow.Index].Cells["NotifyQuantity"].Value, 0);
               double purPrice = Utils.ToDouble(ReturnBllsDataGridView.Rows[ReturnBllsDataGridView.CurrentRow.Index].Cells["PurPrice"].FormattedValue, 0);
               ReturnBllsDataGridView.Rows[ReturnBllsDataGridView.CurrentRow.Index].Cells["NotifyQuantitySum"].Value = notifyQuantity * purPrice;
               notifyandrealQuantityCount();
            }
            else if (ReturnBllsDataGridView.Columns[e.ColumnIndex].Name == "RealQuantity")
            {
               //计算当前行的实退金额
               double notifyQuantity = Utils.ToDouble(ReturnBllsDataGridView.Rows[ReturnBllsDataGridView.CurrentRow.Index].Cells["RealQuantity"].Value, 0);
               double purPrice = Utils.ToDouble(ReturnBllsDataGridView.Rows[ReturnBllsDataGridView.CurrentRow.Index].Cells["PurPrice"].FormattedValue, 0);
               ReturnBllsDataGridView.Rows[ReturnBllsDataGridView.CurrentRow.Index].Cells["RealQuantitySum"].Value = notifyQuantity * purPrice;
               notifyandrealQuantityCount();
            }
            ReturnBllsDataGridView.Refresh();
        }

        /// <summary>
        /// 通知数量与通知金额计算 实退总数量与实退总金额 计算
        /// </summary>
        public void notifyandrealQuantityCount() 
        {
            //计算通知总数量与通知总金额   
            int notifySum = 0;
            double notifyPriceSum = 0;
            //计算实退总数量与实退总金额    
            int realQuantitySum = 0;
            double realQuantityPriceSum = 0;
            

            for (int i = 0; i < ReturnBllsDataGridView.Rows.Count; i++)
            {
                Product p = (Product)ReturnBllsDataGridView.Rows[i].Cells["Product"].Value;
                if (ReturnBllsDataGridView.Rows[i].Cells["NotifyQuantity"].Value != null)
                {
                    string notifyNum = ReturnBllsDataGridView.Rows[i].Cells["NotifyQuantity"].Value.ToString();
                    notifySum += Utils.ToInt(notifyNum, 0);
                    if (returnedBlls == null || (returnedBlls.AuditStatus).Equals(Utils.ToString((Int32)Status.None)))
                    {
                        notifyPriceSum += Utils.ToDouble(notifyNum, 0) * p.PurPrice;
                    }
                    else {
                        double returnPrice = Utils.ToDouble( ReturnBllsDataGridView.Rows[i].Cells["ReturnedPrice"].Value,0);
                        notifyPriceSum += Utils.ToDouble(notifyNum, 0) * returnPrice;
                    }
                }
                if (ReturnBllsDataGridView.Rows[i].Cells["RealQuantity"].Value != null)
                {
                    string notifyNum = ReturnBllsDataGridView.Rows[i].Cells["RealQuantity"].Value.ToString();
                    realQuantitySum += Utils.ToInt(notifyNum, 0);
                    if (returnedBlls == null || (returnedBlls.AuditStatus).Equals(Utils.ToString((Int32)Status.None)))
                    {
                        realQuantityPriceSum += Utils.ToDouble(notifyNum, 0) * p.PurPrice;
                    }
                    else
                    {
                        double returnPrice = Utils.ToDouble(ReturnBllsDataGridView.Rows[i].Cells["ReturnedPrice"].Value, 0);
                        realQuantityPriceSum += Utils.ToDouble(notifyNum, 0) * returnPrice;
                    }
                    
                }
            }
            NotifyQuantitySumText.Text = "通知数量：" + notifySum;
            NotifyQuantityPriceSumText.Text = "通知金额：" + notifyPriceSum;
            RealQuantitySumText.Text = "实退数量：" + realQuantitySum;
            RealQuantityPriceSumText.Text = "实退金额：" + realQuantityPriceSum;
        }

      

        public void initComboBoxDate() 
        {
            //初始化退货分店数据
            Store s = new Store();
            s.StoreType = 2;
            IList<Store> slist = new StoreBLL().findStore(s);
            Store store = new Store();
            store.StoreId = 0;
            store.StoreName = "请选择";
            slist.Insert(0, store);
            ReturnStorecb.DataSource = slist;
            ReturnStorecb.DisplayMember = "StoreName";
            ReturnStorecb.ValueMember = "StoreId";

           

            //初始化税票类型数据
            InvoiceType inv = new InvoiceType();
            inv.InvoiceTypeId = 0;
            inv.InvoiceTypeName = "请选择";
            IList<InvoiceType> ilist = new InvoiceTypeBLL().findInvoiceTypes();
            ilist.Insert(0, inv);
            InvoiceTypecb.DataSource = ilist;
            InvoiceTypecb.DisplayMember = "InvoiceTypeName";
            InvoiceTypecb.ValueMember = "InvoiceTypeId";

        }

        /// <summary>
        /// 初始化窗体数据
        /// </summary>
        public void initFormData()
        {
            initComboBoxDate();
            if (returnedBlls != null)
            {
                ReturnedSntb.Text = returnedBlls.ReturnedSn;//单据编号
                salemanText.Text = "业务员："+ returnedBlls.Salesman;//业务员
                AuditStatusText.Text = "单据状态：" + StatusUtil.getAuditString(Utils.ToInt(returnedBlls.AuditStatus,0));//单据状态
                PrintTimeText.Text = "打印次数：" + returnedBlls.PrintTime;//打印次数
                NotifyPersontb.Text = returnedBlls.NotifyPerson;//通知人
                NotifyDatapk.Value = returnedBlls.NotifyData.Value;//通知时间
                TaxRatetb.Text = returnedBlls.TaxRate;//税率
                CreaterText.Text = "制单人：" + returnedBlls.Account.Username;//创建人
                CreatetimeText.Text = "制单日期：" + string.Format("{0:yyyy/MM/dd HH:mm:ss}", returnedBlls.CreateTime);//创建时间
                if (returnedBlls.AuditAccount != null)
                {
                    AuditUserText.Text = "审核人：" + returnedBlls.AuditAccount.Username;//审核人
                    AuditTimeText.Text = "审核日期：" + string.Format("{0:yyyy/MM/dd HH:mm:ss}", returnedBlls.AuditTime);//审核时间
                }
                Remarktb.Text = returnedBlls.Remark;//通知备注
                AuditRemarktb.Text = returnedBlls.AuditRemark;//审核备注

                //退货分店初始化默认值
                ReturnStorecb.SelectedValue = returnedBlls.ReturnStore.StoreId;
                returnstoretb.Text = returnedBlls.ReturnStore.StoreSn;

                //供应商初始化默认值
                suppliernameText.Text = returnedBlls.Supplier.SupplierName;
                Suppliertb.Text = returnedBlls.Supplier.SupplierCode;

                //税票类型
                InvoiceTypecb.SelectedValue = returnedBlls.InvoiceType.InvoiceTypeId;

                //货品集合
                BindingList<ReturnedProducts> list = new BindingList<ReturnedProducts>(returnedBlls.ReturnedProductsList);
                ReturnBllsDataGridView.DataSource = list;
                ReturnBllsDataGridView.Refresh();

                //按钮控制
                if ((returnedBlls.AuditStatus).Equals(Utils.ToString((Int32)Status.None)))
                {
                    toolStripButtonAddProduct.Enabled = true;
                    toolStripButtonDelProduct.Enabled = true;
                    toolStripButtonrever.Enabled = true;
                    toolStripButtonsave.Enabled = true;
                    toolStripButtondelorder.Enabled = true;
                    toolStripButtonauditpass.Enabled = true;
                    toolStripButtonnopass.Enabled = true;
                    AuditRemarktb.Enabled = true;
                    toolStripButtonsave.Enabled = true;
                }
                else
                {
                    toolStripButtonAddProduct.Enabled = false;
                    toolStripButtonDelProduct.Enabled = false;
                    toolStripButtonrever.Enabled = false;
                    AuditRemarktb.Enabled = false;
                    toolStripButtonsave.Enabled = false;
                }
            }
            notifyandrealQuantityCount();
           
        }

        /// <summary>
        /// 重置窗体数据
        /// </summary>
        public void resetFormData() 
        {
            returnedBlls = null;
            ReturnedSntb.Text = "";//单据编号
            salemanText.Text = "业务员：";//业务员
            AuditStatusText.Text = "单据状态：" + "";//单据状态
            PrintTimeText.Text = "打印次数：" + "";//打印次数
            NotifyPersontb.Text = "";//通知人
            NotifyDatapk.Value = DateTime.Now;//通知时间
            TaxRatetb.Text = "";//税率
            CreaterText.Text = "制单人：" + "";//创建人
            CreatetimeText.Text = "制单日期：" + "";//创建时间
            AuditUserText.Text = "审核人：" + "";//审核人
            AuditTimeText.Text = "审核日期：" + "";//审核时间
            Remarktb.Text = "";//通知备注
            AuditRemarktb.Text = "";//审核备注
            AuditRemarktb.Enabled = false;
            //退货分店
            returnstoretb.Text = "";  
            ReturnStorecb.SelectedValue = 0;
            //供应商
            Suppliertb.Text = "";
            suppliernameText.Text = "";
            

            RealQuantitySumText.Text = "实退数量：";
            RealQuantityPriceSumText.Text = "实退金额：";
            NotifyQuantitySumText.Text = "通知数量：" ;
            NotifyQuantityPriceSumText.Text = "通知金额：";

            //税票类型
            InvoiceTypecb.SelectedValue = 0;

            //货品集合
            ReturnBllsDataGridView.DataSource = null;
            BindingList<ReturnedProducts> list =new BindingList<ReturnedProducts>(new List<ReturnedProducts>());
            ReturnBllsDataGridView.DataSource = list;
            
        }

        /// <summary>
        ///  新建单据按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButtonAddOrder_Click(object sender, EventArgs e)
        {
            resetFormData();
            toolStripButtonAddProduct.Enabled = true;
            toolStripButtonDelProduct.Enabled = true;
            toolStripButtonrever.Enabled = true;
            toolStripButtonsave.Enabled = true;
        }

        /// <summary>
        /// 封装订单信息
        /// </summary>
        public void packagingReturnedBlls(string _type)
        {
            //returnedBlls.ReturnedSn = ReturnedSntb.Text;//单据编号
            if ("update".Equals(_type))
            {
                returnedBlls.Salesman = LoginForm.Account.Username;//业务员
            }
            if ("add".Equals(_type))
            {
                returnedBlls.AuditStatus = ((Int32)Status.None).ToString();//单据状态
                returnedBlls.PrintTime = 0;//打印次数
                returnedBlls.Account = LoginForm.Account;//创建人
                returnedBlls.CreateTime = DateTime.Now;//创建时间
                returnedBlls.OrgDepId = LoginForm.DepId;//归属部门
                returnedBlls.OrgId = LoginForm.StoreId;//归属门店
                returnedBlls.Salesman = LoginForm.Account.Username;//业务员
            }
            returnedBlls.NotifyPerson = NotifyPersontb.Text;//通知人
            returnedBlls.NotifyData = NotifyDatapk.Value;//通知时间
            returnedBlls.TaxRate = TaxRatetb.Text;//税率
            
            if ("audit".Equals(_type))
            {
                returnedBlls.AuditAccount = LoginForm.Account;//审核人
                returnedBlls.AuditTime = DateTime.Now;//审核时间
            }
            returnedBlls.ReturnStore = (Store)ReturnStorecb.SelectedItem;//退货分店
            returnedBlls.Supplier = (Supplier)Suppliertb.Tag;//供应商
            returnedBlls.InvoiceType = (InvoiceType)InvoiceTypecb.SelectedItem;//税票类型
            returnedBlls.ReturnedDate = null;//退货时间

            returnedBlls.Remark =Remarktb.Text;//通知备注
            returnedBlls.AuditRemark = AuditRemarktb.Text;//审核备注
            //货品集合
            returnedBlls.ReturnedProductsList = (BindingList<ReturnedProducts>)ReturnBllsDataGridView.DataSource;
        }

        /// <summary>
        /// 下一张单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton8_Click(object sender, EventArgs e)
        {
            loadData(pageNo + 1);
        }

        /// <summary>
        /// 退货分店选择事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ReturnStorecb_SelectedIndexChanged(object sender, EventArgs e)
        {
            returnstoretb.Text = ((Store)ReturnStorecb.SelectedItem).StoreSn;
        }

       

        /// <summary>
        /// 保存退货单
        /// </summary>
        /// <param name="_type"></param>
        /// <returns></returns>
        public bool save_returnOrders(string _type)
        {
            
            if ("add".Equals(_type))
            {
                string ordersn = new BillSNGenerator().GeneratorBillSn(BillType.Return, BillSource.DistributionCenter, ((Store)ReturnStorecb.SelectedItem).StoreId);
                returnedBlls = new ReturnedBlls();
                returnedBlls.ReturnedSn = ordersn;
                packagingReturnedBlls(_type);
                return new ReturnOrdersBll().saveReturnOrders(returnedBlls);
            }
            else
            {
                packagingReturnedBlls(_type);
                return new ReturnOrdersBll().updateReturnOrders(returnedBlls);
            }
        }

        /// <summary>
        /// 保存单据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton12_Click(object sender, EventArgs e)
        {
            bool flag = false;
            if (returnedBlls != null)
            {
                flag = save_returnOrders("update");
            }
            else
            {
                flag = save_returnOrders("add");
            }
            if (flag) 
            {
                MessageBox.Show("保存成功");
                initFormData();
            }
        }

        /// <summary>
        /// 查找数据
        /// </summary>
        /// <param name="start"></param>
        public void loadData(int start)
        {
            PageModel<ReturnedBlls> pageModellist = null;// new ReturnOrdersBll().findPageList(null, start, 1);
            int pageCount = pageModellist.PageCount;//总页数
            pageNo = start;//当前页数
            if (pageNo == 0)
                lastPageButton.Enabled = false;
            else
                lastPageButton.Enabled = true;
            if ((pageNo + 1) == pageCount)
                nextPageButton.Enabled = false;
            else
                nextPageButton.Enabled = true;
           
            if (pageModellist.Results.Count > 0)
            {
                returnedBlls = pageModellist.Results[0];
                initFormData();
            }
        }

        /// <summary>
        /// 单据查找按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            loadData(0);
        }

        /// <summary>
        /// DataGridView单元格格式化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ReturnBllsDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            try
            {
                int totalRows = ReturnBllsDataGridView.Rows.Count;
                int curRow = e.RowIndex;
                if (curRow < totalRows)
                {
                    ReturnedProducts p = ReturnBllsDataGridView.Rows[curRow].DataBoundItem as ReturnedProducts;
                    if (p != null && p.Product != null)
                    {
                        if (ReturnBllsDataGridView.Columns[e.ColumnIndex].Name == "Barcode")
                        {
                            e.Value = p.Product.Barcode;
                        }
                        else if (ReturnBllsDataGridView.Columns[e.ColumnIndex].Name == "ProductCode")
                        {
                            e.Value = p.Product.ProductCode;
                        }
                        else if (ReturnBllsDataGridView.Columns[e.ColumnIndex].Name == "ProductName")
                        {
                            e.Value = p.Product.ProductName;
                        }
                        else if (ReturnBllsDataGridView.Columns[e.ColumnIndex].Name == "PackSpec")
                        {
                            e.Value = p.Product.PackSpec;
                        }
                        else if (ReturnBllsDataGridView.Columns[e.ColumnIndex].Name == "PurPrice")
                        {
                            if (returnedBlls == null || (returnedBlls.AuditStatus).Equals(Utils.ToString((Int32)Status.None)))
                                e.Value = p.Product.PurPrice;
                            else
                                e.Value = p.ReturnedPrice;
                        }
                        else if (ReturnBllsDataGridView.Columns[e.ColumnIndex].Name == "DefUnit")
                        {
                            if (p.Product.DefUnit != null)
                                e.Value = p.Product.DefUnit.UnitName;
                        }
                        else if (ReturnBllsDataGridView.Columns[e.ColumnIndex].Name == "NotifyQuantitySum")
                        {
                            if (returnedBlls == null || (returnedBlls.AuditStatus).Equals(Utils.ToString((Int32)Status.None)))
                                e.Value = (p.Product.PurPrice) * Utils.ToDouble((p.NotifyQuantity), 0);
                            else
                                e.Value = (Utils.ToDouble(p.ReturnedPrice, 0)) * Utils.ToDouble((p.NotifyQuantity), 0);

                        }
                        else if (ReturnBllsDataGridView.Columns[e.ColumnIndex].Name == "RealQuantitySum")
                        {
                            if (returnedBlls == null || (returnedBlls.AuditStatus).Equals(Utils.ToString((Int32)Status.None)))
                                e.Value = (p.Product.PurPrice) * Utils.ToDouble((p.RealQuantity), 0);
                            else
                                e.Value = (Utils.ToDouble(p.ReturnedPrice, 0)) * Utils.ToDouble((p.RealQuantity), 0);

                        }
                    }
                }
            }
            catch (Exception)
            {
                
            }
        }

        /// <summary>
        /// 上一张单按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lastPageButton_Click(object sender, EventArgs e)
        {
            loadData(pageNo - 1);
        }

        /// <summary>
        /// 删除按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            if (returnedBlls != null)
            {
                bool flag = new ReturnOrdersBll().delReturnOrders(returnedBlls);
                if (flag)
                {
                    MessageBox.Show("删除成功!");
                    resetFormData();
                }
            }
        }



        /// <summary>
        /// 拒审按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            returnedBlls.AuditStatus = ((Int32)Status.AuditNoPass).ToString();
            for (int i = 0; i < ReturnBllsDataGridView.Rows.Count; i++)
            {
                Product p = (Product)ReturnBllsDataGridView.Rows[i].Cells["Product"].Value;
                ReturnBllsDataGridView.Rows[i].Cells["ReturnedPrice"].Value = p.PurPrice;
            }
            save_returnOrders("Audit");
        }

        /// <summary>
        /// 单据审核按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            returnedBlls.AuditStatus = ((Int32)Status.AuditPass).ToString();
            for (int i = 0; i < ReturnBllsDataGridView.Rows.Count; i++)
            {
                Product p = (Product)ReturnBllsDataGridView.Rows[i].Cells["Product"].Value;
                ReturnBllsDataGridView.Rows[i].Cells["ReturnedPrice"].Value = p.PurPrice;
            }
            save_returnOrders("Audit");
        }

        /// <summary>
        /// 还原按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton14_Click(object sender, EventArgs e)
        {
            if (returnedBlls != null)
            {
                int returnedId = returnedBlls.ReturnedId;
                resetFormData();
                returnedBlls = new ReturnOrdersBll().Get(returnedId);
                initFormData();
            }
        }

        /// <summary>
        /// 供应商编辑事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Suppliertb_TextChanged(object sender, EventArgs e)
        {
            string suppliercode = Suppliertb.Text;
            if (suppliercode != null && !"".Equals(suppliercode))
            {
                Supplier su = new SupplierBLL().FindSupplier(suppliercode);
                if (su != null)
                {
                    suppliernameText.Text = su.SupplierName;
                    Suppliertb.Tag = su;
                }
                else
                {
                    suppliernameText.Text = "";
                    Suppliertb.Tag = null;
                }
            }
        }

        /// <summary>
        /// 退出按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButtonexit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
